package com.cwt_taxi_xa;

import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.TextView;
import com.cwt_taxi_xa.model.EventInfo;
import com.cwt_taxi_xa.protocol.DispatchCenterUsers;
import com.cwt_taxi_xa.protocol.Encoder;
import com.cwt_taxi_xa.util.ToastUtils;
/**
 * 抢答界面
 * @author ferch
 *
 */
public class EventActivity extends CWTBaseActivity implements OnClickListener{
	private static final String TAG = "EventActivity";
	public TextView message_info,cancel,submit,time;
	public static EventActivity instance = null;
	public static EventInfo info;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_event);
		instance=EventActivity.this;

		setupViews();
		addListener();
		initData();
	}

	private void initData() {
		// TODO Auto-generated method stub
		info = (EventInfo) getIntent().getSerializableExtra("info");
		message_info.setText(info.getText());
		if(info.getIsDone() == 1){
			submit.setText("事件已报告");
			submit.setClickable(false);
		}
	}

	private void setupViews() {
		// TODO Auto-generated method stub
		message_info = (TextView)this.findViewById(R.id.message_info);
		cancel = (TextView)this.findViewById(R.id.cancel);
		time = (TextView)this.findViewById(R.id.time);
		submit = (TextView)this.findViewById(R.id.submit);
	}

	private void addListener() {
		// TODO Auto-generated method stub
		submit.setOnClickListener(this);
		cancel.setOnClickListener(this);
	}

	@Override
	protected void onResume() {
		// TODO Auto-generated method stub
		super.onResume();
	}
	@Override
	public void onClick(View view) {
		switch (view.getId()) {
			case R.id.submit:
				if(info.getIsDone() == 1){
					ToastUtils.showToastForCustom("您已经提交过报告，无需重复提交");
				}else{
					DispatchCenterUsers.witeMsg(Encoder.getEventReport(info.getId()), 0);
				}
				break;
			case R.id.cancel:
				EventActivity.this.finish();
				break;

			default:
				break;
		}
	}

	private Handler handler = new Handler() {
		@Override
		public void handleMessage(Message msg) {
			int what = msg.what;
			if (what == 102) {
				int obj = (Integer) msg.obj;
				if(obj < 0){
					finish();
				}
				time.setText(""+obj);
			}
		}
	};

	@Override
	protected void onDestroy() {
		super.onDestroy();
		instance = null;
	}

	@Override
	public void setStatus(int index, boolean status) {
		// TODO Auto-generated method stub

	}

	@Override
	public void sendMsg(int type, Object obj) {
		// TODO Auto-generated method stub

	}
}
